﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ENG.EngStartQueue.Counters
{
  internal class CultureCounterData
  {
    public string Category { get; private set; }
    public string Counter { get; private set; }
    public string Instance { get; private set; }
    public bool isMaxGood { get; private set; }
    public int? okValue { get; private set; }

    public static CultureCounterData Load(XElement item)
    {
      CultureCounterData ret = new CultureCounterData();

      ret.Category = Root.GetAttribute(item, "category");
      ret.Counter = Root.GetAttribute(item, "counter");
      ret.Instance = Root.GetAttribute(item, "instance");
      string p = Root.GetAttribute(item, "isMaxGood");
      switch (p)
      {
        case "true":
          case "1":
          ret.isMaxGood = true;
          break;
        case "false":
          case "0":
          ret.isMaxGood = false;
          break;
      }
      p = Root.GetAttribute(item, "okValue");
      if (p == null)
        ret.okValue = null;
      else
      {
        int i;
        if (int.TryParse(p, out i))
          ret.okValue = i;
      }

      return ret;
    }
  }
}
